function getQueryString(name) {  //获取url参数
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i")
    var r = window.location.search.substr(1).match(reg)
    if (r != null) return unescape(r[2])
    return null
}

function formatSeconds(value) {
    var theTime = parseInt(value)// 秒
    var theTime1 = 0// 分
    var theTime2 = 0// 小时
    if (theTime > 60) {
        theTime1 = parseInt(theTime / 60)
        theTime = parseInt(theTime % 60)
        if (theTime1 > 60) {
            theTime2 = parseInt(theTime1 / 60)
            theTime1 = parseInt(theTime1 % 60)
        }
    }
    
    var result
    if (parseInt(theTime) < 10) {
        if (parseInt(theTime) < 1) {
            result = "0" + 1
        } else {
            result = "0" + parseInt(theTime)
        }
    } else {
        result = "" + parseInt(theTime)
    }
    
    
    if (theTime1 > 0) {
        if (parseInt(theTime1) < 10) {
            result = "0" + parseInt(theTime1) + ":" + result
        } else {
            result = "" + parseInt(theTime1) + ":" + result
        }
    } else {
        result = "00:" + result
    }
    
    return result
}

//设置cookie

function setCookie(c_name, value, expiredays) {
    var exdate = new Date()
    exdate.setDate(exdate.getDate() + expiredays)
    document.cookie = c_name + "=" + escape(value) +
        ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
}


//获取cookie

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        var c_start = document.cookie.indexOf(c_name + "=")
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1
            var c_end = document.cookie.indexOf(";", c_start)
            if (c_end == -1) c_end = document.cookie.length
            return unescape(document.cookie.substring(c_start, c_end))
        }
    }
    return ""
}
export {
    getQueryString, formatSeconds, getCookie, setCookie
}
